package com.atguigu.gmall.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @Author: 小兰
 * @Date: 2023/4/25 20:45
 */
@Controller
public class IndexController {
    @Autowired
    private ProductFeignClient productFeignClient;

    /**
     * 渲染首页
     * @param model
     * @return
     */
    @GetMapping({"","/","index.html"})
    public String indexHtml(Model model){
        //远程调用商品微服务获取首页分类数据


        //  todo  首页其他数据:广告轮播图;推荐商品等,都应该调用对应服务来获取
        //todo 如果接口多,,用completablefuture并行调用
        List<JSONObject> baseCategoryList = productFeignClient.getBaseCategoryList();
        model.addAttribute("list", baseCategoryList);
        return "/index/index";
    }
}
